// Copyright (c) 2009 Mike Haight, Andy Kipp
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.


#include "stdafx.h"


Size::Size(float argWidth, float argHeight) : mWidth(argWidth), mHeight(argHeight)
{
}


float Size::Height::get(void)
{
    return mHeight;
}


void Size::Height::set(float value)
{
    mHeight = value;
}


float Size::Width::get(void)
{
    return mWidth;
}


void Size::Width::set(float value)
{
    mWidth = value;
}


bool Size::Equals(Object^ argObject)
{
    if (Size::typeid == argObject->GetType())
    {
        Size^ location = (Size^)argObject;
        if ((mWidth == location->mWidth) && (mHeight == location->mHeight))
        {
             return true;
        }
    }

    return false;
}


String^ Size::ToString(void)
{
    return String::Format("({0},{1})", mWidth, mHeight);
}


bool Size::IsEmpty(void)
{
    if (0 == mWidth && 0 == mHeight)
    {
        return true;
    }

    return false;
}


Coordinates::Size Size::Parse(String^ argText)
{
    if (nullptr == argText)
    {
        throw gcnew ArgumentNullException();
    }

    array<String^>^ elements = argText->Split(',');

    if (!elements->Length.Equals(2))
    {
        throw gcnew FormatException();
    }

    return Coordinates::Size(
        float::Parse(elements[0]),
        float::Parse(elements[1]));
}